package com.A1908.servlet;

import com.A1908.entity.MyAttend;
import com.A1908.service.MyAttendService;
import com.A1908.service.impl.MyAttendServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = {"/myAttend"})
public class MyAttendServlet extends HttpServlet {
    MyAttendService myAttendService = new MyAttendServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        String opr = request.getParameter("opr");
        PrintWriter out = response.getWriter();

        if ("list".equals(opr) || opr == null){
            MyAttend myAttend = new MyAttend();
            myAttend.setMyUserID((int) request.getSession().getAttribute("userID"));
            List<MyAttend> list = myAttendService.findAllMyAttend(myAttend);
            out.print(JSON.toJSONString(list));
        }
        out.close();
    }
}
